package sf.r2dbc.rowmapper;

import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
import sf.r2dbc.sql.R2dbcConvertUtils;

/**
 * 单值转换,主要是基本类型,String等.
 * @param <T>
 */
public class R2dbcSingleColumnRowMapper<T> implements R2dbcRowMapper<T> {

    private Class<T> targetClass;

    public R2dbcSingleColumnRowMapper(Class<T> targetClass) {
        this.targetClass = targetClass;
    }

    @Override
    public T apply(Row rs, RowMetadata metadata) {
        return R2dbcConvertUtils.get(rs.get(0), null, targetClass, null, null);
    }

}
